/**
 * huize Service Inc
 * All Rights Reserved @2018
 */
package com.huize.zhike.framework.common.enumeration;

import com.huize.ladon.apm.common.enums.EnumInterface;
import org.apache.commons.lang3.StringUtils;

/**
 * 描述: 缓存值变化
 *
 * @author tianyuliang
 * @version $Id: CacheStatusEnum.java, v0.1 2020/11/24
 */
public enum CacheStatusEnum implements EnumInterface {

    /**
     * 缓存值变化
     */
    CHANGE("change", "变更"),

    /**
     * 缓存值不做改变,查询
     */
    QUERY("query", "查询");

    private String status;

    private String desc;

    CacheStatusEnum(String status, String desc) {
        this.status = status;
        this.status = status;
        this.desc = desc;
    }

    public static CacheStatusEnum of(String status) {
        if (StringUtils.isBlank(status)) {
            return QUERY;
        }

        for (CacheStatusEnum statusEnum : CacheStatusEnum.values()) {
            if (statusEnum.getStatus().equalsIgnoreCase(status.trim())) {
                return statusEnum;
            }
        }
        return QUERY;
    }

    public static Boolean isChange(String status) {
        return of(status) == CHANGE;
    }

    public static Boolean isChange(CacheStatusEnum statusEnum) {
        return statusEnum != null && statusEnum == CHANGE;
    }

    public static Boolean isQuery(String status) {
        return of(status) == QUERY;
    }

    public static Boolean isQuery(CacheStatusEnum statusEnum) {
        return statusEnum != null && statusEnum == QUERY;
    }

    public String getStatus() {
        return this.status;
    }

    @Override
    public String getCode() {
        return this.status;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    @Override
    public String toString() {
        return String.format("(%s,%s)", getCode(), getDesc());
    }

}
